2020-2021 Sunseeker Telemetry and Lighting System
comp_e_ex1_outputToggleVcompVsVref2V.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430FR59xx Demo - COMPE Toggle from LPM4; input channel C2;
34 // Vcompare is compared against the internal reference 2.0V
35 //
36 // Description: Use CompE (input channel C2) and internal reference to
37 // determine if input'Vcompare'is high or low. When Vcompare exceeds 2.0V
38 // COUT goes high and when Vcompare is less than 2.0V then COUT goes low.
39 // P3.5/COUT is connected internally to an LED; it will toggle accordingly.
40 //
41 // MSP430FR5969
42 // ------------------
43 // /|\| |
44 // | | |
45 // --|RST P1.2/C2|<--Vcompare
46 // | |
47 // | P3.5/COUT|----> 'high'(Vcompare>2.0V); 'low'(Vcompare<2.0V)
48 // | | |
49 // | | | LED 'ON'(Vcompare>2.0V); 'OFF'(Vcompare<2.0V)
50 // | |
51 //
52 
53 //******************************************************************************
54 
55 #include "driverlib.h"
56 
57 void main(void)
58 {
59  //Stop WDT
60  WDT_A_hold(WDT_A_BASE);
61 
62  //Set P3.5 as Ternary Module Function Output.
63  /*
64 
65  * Select Port 3
66  * Set Pin 5 to output Ternary Module Function, (COUT).
67  */
68  GPIO_setAsPeripheralModuleFunctionOutputPin(
69  GPIO_PORT_P3,
70  GPIO_PIN5,
71  GPIO_TERNARY_MODULE_FUNCTION
72  );
73 
74  /*
75  * Disable the GPIO power-on default high-impedance mode to activate
76  * previously configured port settings
77  */
78  PMM_unlockLPM5();
79 
80  //Initialize the Comparator E module
81  /* Base Address of Comparator E,
82  * Pin CE2 to Positive(+) Terminal,
83  * Reference Voltage to Negative(-) Terminal,
84  * Normal Power Mode,
85  * Output Filter On with minimal delay,
86  * Non-Inverted Output Polarity
87  */
88 
89  Comp_E_initParam param = {0};
90  param.posTerminalInput = COMP_E_INPUT2;
91  param.negTerminalInput = COMP_E_VREF;
92  param.outputFilterEnableAndDelayLevel = COMP_E_FILTEROUTPUT_OFF;
93  param.invertedOutputPolarity = COMP_E_NORMALOUTPUTPOLARITY;
94  Comp_E_init(COMP_E_BASE, &param);
95 
96  //Set the reference voltage that is being supplied to the (-) terminal
97  /* Base Address of Comparator E,
98  * Reference Voltage of 2.0 V,
99  * Lower Limit of 2.0*(32/32) = 2.0V,
100  * Upper Limit of 2.0*(32/32) = 2.0V
101  */
102  Comp_E_setReferenceVoltage(COMP_E_BASE,
103  COMP_E_VREFBASE2_0V,
104  32,
105  32
106  );
107 
108  //Disable Input Buffer on P1.2/CE2
109  /* Base Address of Comparator E,
110  * Input Buffer port
111  * Selecting the CEx input pin to the comparator
112  * multiplexer with the CEx bits automatically
113  * disables output driver and input buffer for
114  * that pin, regardless of the state of the
115  * associated CEPD.x bit
116  */
117  Comp_E_disableInputBuffer(COMP_E_BASE,
118  COMP_E_INPUT2);
119 
120  //Allow power to Comparator module
121  Comp_E_enable(COMP_E_BASE);
122 
123  __delay_cycles(400); // delay for the reference to settle
124 
125  __bis_SR_register(LPM4_bits); // Enter LPM4
126  __no_operation(); // For debug
127 }
MPU_initThreeSegmentsParam param
__no_operation()
__delay_cycles(500000)